Jump to content


Photo

Java Work Start Cheyyali..


  • Please log in to reply
40 replies to this topic

#1 PMR aka OM

PMR aka OM

    Director, Andhra Friends

  • Members
  • 25,056 posts

Posted 02 November 2011 - 08:49 PM

evaru co-operating ikkadaa.. naa class lo homework saami idhi..



1.4 What is a source program? What is a compiler?

Ans ::: A program written in a high-level language is called a source program or source code.
Since a computer cannot understand a source program, a program called a compiler is used to
translate it into a machine-language program.


1.5 What is the JVM?
Ans :: The Java language is a high-level language while Java bytecode is a low-level language. The bytecode

is similar to machine instructions but is architecture neutral and can run on any platform that has
a Java Virtual Machine (JVM).
JVM is the layer in between the byte code of instruction set of the actual machine with diffferent kinds of operating systems and the Actual Java program which was written irresoective of the machine its gonna deployed on..



1.11 Explain the Java keywords. List some Java keywords you learned in this
chapter 1( JAVA PROGRAMMING )
COMPREHENSIVE VERSION Eighth Edition Y. Daniel Liang.


Ans :: Reserved words, or keywords, have a specific meaning to the compiler and cannot be used
for other purposes in the program.
public, static, void, null, class,


1.13 What is the Java source filename extension, and what is the Java bytecode filename
extension?
. java is source file name extnsion and .class is a byte code genearted by the compiler. ( Please validate>>>)

1.16 The following program is wrong. Reorder the lines so that the program displays
morning followed by afternoon.
public static void main(String[] args) {
}
public class Welcome {
System.out.println("afternoon");
System.out.println("morning");
}

Ans ::
public class Welcome

{
public static void main(String[] args)
{
System.out.println("afternoon");


System.out.println("morning");
}
}







1.17 Identify and fix the errors in the following code:
public class Welcome
{
public void Main(String[] args)
{
System.out.println('Welcome to Java!);
}
)
Ans ::

public class Welcome
{
public void Main(String[] args)
{
System.out.println("Welcome to Java!");
}
}


1.2 (Displaying five messages) Write a program that displays Welcome to Java five times.

Ans::

public class Test
{ int i =1;
public static void main(String[] args)
{
while(i<=5)
{
System.out.println("Welcome to Java");
i++;
}
}





Chapter 2:


2.1 Which of the following identifiers are valid? Which are Java keywords?
applet, Applet, a++, ––a, 4#R, $4, #44, apps
class, public, int, x, y, radius


2.3 What are the benefits of using constants? Declare an int constant SIZE with
value 20.



2.4 Assume that int a = 1 and double d = 1.0, and that each expression is independent.
What are the results of the following expressions?
a = 46 / 9;
a = 46 % 9 + 4 * 4 - 2;
a = 45 + 43 % 5 * (23 * 3 % 2);
a %= 3 / a + 3;
d = 4 + d * d + 4;
d += 1.5 * 3 + (++a);
d -= 1.5 * 3 + a++;




2.5 Show the result of the following remainders.
56 % 6
78 % -4
-34 % 5
-34 % -5
5 % 1
1 % 5



2.9 Are the following statements correct? If so, show the output.
System.out.println("25 / 4 is " + 25 / 4);
System.out.println("25 / 4.0 is " + 25 / 4.0);
System.out.println("3 * 2 / 4 is " + 3 * 2 / 4);
System.out.println("3.0 * 2 / 4 is " + 3.0 * 2 / 4);

2.10 ..
Image post chestanu next thread lo.. update chestaanu appudu..

#2 PMR aka OM

PMR aka OM

    Director, Andhra Friends

  • Members
  • 25,056 posts

Posted 02 November 2011 - 08:50 PM

2.14 Identify and fix the errors in the following code:
1 public class Test {
2 public void main(string[] args) {
3 int i;
4 int k = 100.0;
5 int j = i + 1;
6
7 System.out.println("j is " + j + " and
8 k is " + k);
9 }
10 }
2.15 How do you obtain the current minute using the System.currentTimeMillis()
method?



Problems::



2.7* (Finding the number of years) Write a program that prompts the user to enter the
minutes (e.g., 1 billion) and displays the number of years and days for the minutes.
For simplicity, assume a year has 365 days. Here is a sample run:


Enter the number of minutes: 1000000000 {Enter}
1000000000 minutes is approximately 1902 years and 214 days.

#3 PMR aka OM

PMR aka OM

    Director, Andhra Friends

  • Members
  • 25,056 posts

Posted 02 November 2011 - 08:51 PM

2.1 (Converting Celsius to Fahrenheit) Write a program that reads a Celsius degree in
double from the console, then converts it to Fahrenheit and displays the result. The
formula for the conversion is as follows:
fahrenheit = (9 / 5) * celsius + 32
Hint: In Java, 9 / 5 is 1, but 9.0 / 5 is 1.8.
Here is a sample run:
sample runs
learn from examples
Enter a degree in Celsius:
43 Celsius is 109.4 Fahrenheit


Ans ::

Refernce source ::

import java.util.Scanner;

public class FahrenheitToCelsius {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);

System.out.print("Enter a degree in Fahrenheit: ");
double fahrenheit = input.nextDouble();

// Convert Fahrenheit to Celsius
double celsius = * (fahrenheit - 32);
System.out.println("Fahrenheit " + fahrenheit + " is " +
celsius + " in Celsius");

}
}

Solution::


import java.util.Scanner;

public class CelsiusToFahrenheit
{
public static void main(String[] args)
{
Scanner input = new Scanner(System.in);
System.out.print("Enter a degree in Celsius: ");
double celsius = input.nextDouble();

// Convert Celsius to Fahrenheit
double fahrenheit = (9.0/ 5) * celsius + 32 .0
System.out.println("Celsius " +celsius + " is " +fahrenheit+ " in Fahrenheit");
}
}

#4 PMR aka OM

PMR aka OM

    Director, Andhra Friends

  • Members
  • 25,056 posts

Posted 02 November 2011 - 08:52 PM

All kinds of answers will be accepted.. Best voted answer will be posted to the professor..

naa grades ni e DB ki ankitham chestaanu...

#5 PMR aka OM

PMR aka OM

    Director, Andhra Friends

  • Members
  • 25,056 posts

Posted 02 November 2011 - 09:25 PM

Chapter 1 Assignment done .


repu office lo koorchoni migilina pani poorthi cheyyalemo..

manchigaa DB lo correct chesthey evadiki anumaanam raakunda pani chesukovachiu,,

#6 akhisakhi

akhisakhi

    Hero

  • Members
  • 2,882 posts

Posted 02 November 2011 - 09:29 PM

gp

#7 PMR aka OM

PMR aka OM

    Director, Andhra Friends

  • Members
  • 25,056 posts

Posted 02 November 2011 - 09:40 PM

2.1 Which of the following identifiers are valid? Which are Java keywords?


Identifiers are for naming variables, constants, methods, classes, and packages. Descriptive identifiers make programs easy to read.
An identifier is a sequence of characters that consists of letters, digits, underscores (_), and dollar signs ($).
An identifier must start with a letter, an underscore (_), or a dollar sign ($). It cannot start with a digit. An identifier cannot be a keyword.

applet, Applet, a++, ––a, 4#R, $4, #44, apps , class, public, int, x, y, radius


class, public,int, - keywords

apps,radius, $4, x, y, applet, Applet, - Identifiers

#8 K.A.Paul

K.A.Paul

    Celebrity

  • Members
  • 14,491 posts

Posted 02 November 2011 - 10:49 PM

emi ardam kaledu baa neku emi kavalo

#9 Alexander

Alexander

    PADMASHREE

  • Members
  • 57,710 posts

Posted 02 November 2011 - 10:55 PM

gp


CITI_c$y CITI_c$y CITI_c$y

#10 PMR aka OM

PMR aka OM

    Director, Andhra Friends

  • Members
  • 25,056 posts

Posted 02 November 2011 - 10:58 PM

emi ardam kaledu baa neku emi kavalo



akkada first chapter antey 1.* answers raasaanu baa..

emina corrections untey cheppu.. update chestaanu.. .

inka 2nd chapter lo chalaa varaku answers kuda vetakaali,, nee daggara vatiki answers untey post cheseyi...

nenu repu edho oka time lo anni chusi update chesukuni maa. vaadiki submit chesestaanu..

#11 Little Star

Little Star

    Proud Supporter of BJP!!!

  • Members
  • 46,436 posts

Posted 02 November 2011 - 11:34 PM

RePost..

#12 Scrooge

Scrooge

    VIP

  • Members
  • 71,989 posts

Posted 03 November 2011 - 12:02 AM

:3D_Smiles: :3D_Smiles: :3D_Smiles:

answer lu ani evo unai kada..... emi kavali inka

#13 K.A.Paul

K.A.Paul

    Celebrity

  • Members
  • 14,491 posts

Posted 03 November 2011 - 12:10 AM

2.2


public static final int SIZE = 10;

2.4


1. A=5
2. A=15
3. A=1
4. D=9.0
5. D=7.5
6. D=-4.5


2.5

1. 2
2. 2
3. -4
4. -4
5. 0
6. 1


2.9
1. 6
2. 6.25
3.1
4. 1.5


2.1 program:

import java.util.Scanner;


public class CelsiusToFahrenheit {

/**
* @param args
*/
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.print("Enter a degree in Celsius: ");
double celsius = input.nextDouble();

// Convert Celsius to Fahrenheit
double fahrenheit = (9.0/ 5) * celsius + 32.0;
System.out.println("Celsius " +celsius + " is " +fahrenheit+ " in Fahrenheit");
}

}


2.7 program


import java.util.Scanner;
import java.util.concurrent.TimeUnit;


public class Convert {

/**
* @param args
*/
public static void main(String[] args) {

long sec, min, day, wks, mnths, yrs;
long millis = 0;
Scanner input = new Scanner(System.in);
System.out.print("Enter a time in seconds: ");
millis=input.nextLong();

min = (millis / 60);
day = (min / 24);
wks = (day / 52);
mnths = (wks / 30);
yrs = (mnths / 12);
StringBuilder sb = new StringBuilder(64);
sb.append(yrs);
sb.append(" Years ");
sb.append(mnths);
sb.append(" mnths ");
sb.append(wks);
sb.append(" weeks ");
sb.append(day);
sb.append(" days");
sb.append(min);
sb.append("mins ");
System.out.println("Time="+ sb.toString());




}
}

#14 Scrooge

Scrooge

    VIP

  • Members
  • 71,989 posts

Posted 03 November 2011 - 12:12 AM

2.2


public static final int SIZE = 10;

2.4


1. A=5
2. A=15
3. A=1
4. D=9.0
5. D=7.5
6. D=-4.5


2.5

1. 2
2. 2
3. -4
4. -4
5. 0
6. 1


2.9
1. 6
2. 6.25
3.1
4. 1.5


2.1 program:

import java.util.Scanner;


public class CelsiusToFahrenheit {

/**
* @param args
*/
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.print("Enter a degree in Celsius: ");
double celsius = input.nextDouble();

// Convert Celsius to Fahrenheit
double fahrenheit = (9.0/ 5) * celsius + 32.0;
System.out.println("Celsius " +celsius + " is " +fahrenheit+ " in Fahrenheit");
}

}


2.7 program


import java.util.Scanner;
import java.util.concurrent.TimeUnit;


public class Convert {

/**
* @param args
*/
public static void main(String[] args) {

long sec, min, day, wks, mnths, yrs;
long millis = 0;
Scanner input = new Scanner(System.in);
System.out.print("Enter a time in seconds: ");
millis=input.nextLong();

min = (millis / 60);
day = (min / 24);
wks = (day / 52);
mnths = (wks / 30);
yrs = (mnths / 12);
StringBuilder sb = new StringBuilder(64);
sb.append(yrs);
sb.append(" Years ");
sb.append(mnths);
sb.append(" mnths ");
sb.append(wks);
sb.append(" weeks ");
sb.append(day);
sb.append(" days");
sb.append(min);
sb.append("mins ");
System.out.println("Time="+ sb.toString());




}
}



nuvvu pada learning center ki ....... repati nunchi java classes start seyi #/{-

#15 K.A.Paul

K.A.Paul

    Celebrity

  • Members
  • 14,491 posts

Posted 03 November 2011 - 12:15 AM



nuvvu pada learning center ki ....... repati nunchi java classes start seyi #/{-


next mnth nunchi start chesta baa &D_@@