Jump to content

Java Work Start Cheyyali..


PMREDDY19

Recommended Posts

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
[b]chapter 1( JAVA PROGRAMMING )[/b]
[b]COMPREHENSIVE VERSION Eighth Edition Y. Daniel Liang.[/b]


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,


[color=#ff0000][b]1.13 What is the Java source filename extension, and what is the Java bytecode filename[/b][/color]
[color=#ff0000][b]extension?[/b][/color]
[color=#000000][b] . java is source file name extnsion and .class is a byte code genearted by the compiler. ( Please validate>>>)[/b][/color]

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

Ans ::
[color=#008000][b]public class Welcome[/b][/color]

[color=#008000][b]{[/b][/color]
[color=#008000][b] public static void main(String[] args)[/b][/color]
[color=#008000][b] {[/b][/color]
[b] System.out.println("afternoon");[/b]


[b] System.out.println("morning");[/b]
[b] }[/b]
[b]}[/b]







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

public class Welcome
{
public void Main(String[] args)
{
System.out.println[color=#008000][b]("Welcome to Java!");[/b][/color]
[color=#008000][b]}[/b][/color]
[color=#008000][b]}[/b][/color]


[color=#ff0000][b]1.2 (Displaying five messages) Write a program that displays Welcome to Java five [/b][/color][b]times. [/b]

[b]Ans::[/b]

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..

Link to comment
Share on other sites

  • Replies 40
  • Created
  • Last Reply

Top Posters In This Topic

  • PMREDDY19

    19

  • k2s

    5

  • K.A.Paul

    5

  • htnamus

    4

Top Posters In This Topic

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.

Link to comment
Share on other sites

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


[b]Ans ::[/b]

[b]Refernce source ::[/b]

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");

}
}

[b]Solution::[/b]


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
[b] double fahrenheit = (9.0/ 5) * celsius + 32 .0[/b]
System.out.println("Celsius " +celsius + " is " +fahrenheit+ " in Fahrenheit");
}
}

Link to comment
Share on other sites

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

naa grades ni e DB ki ankitham chestaanu...

Link to comment
Share on other sites

Chapter 1 Assignment done .


repu office lo koorchoni migilina pani poorthi cheyyalemo..

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

Link to comment
Share on other sites

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, [b]a++, ––a, 4#R, [/b]$4, [b]#44,[/b] apps , class, public, int, x, y, radius


class, public,int[b], - keywords[/b]

apps,radius, $4, x, y, [color=#ff8c00][b]applet, Applet,[/b][/color] - Identifiers

Link to comment
Share on other sites

[quote name='K.A.Paul' timestamp='1320295750' post='3059492']
emi ardam kaledu baa neku emi kavalo
[/quote]


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..

Link to comment
Share on other sites

2.2


[b] public static final int SIZE = 10;[/b]

2.4


[b]1. A=5[/b]
[b]2. A=15[/b]
[b]3. A=1[/b]
[b]4. D=9.0[/b]
[b]5. D=7.5[/b]
[b]6. D=-4.5[/b]


2.5

[b]1. 2[/b]
[b]2. 2[/b]
[b]3. -4[/b]
[b]4. -4[/b]
[b]5. 0[/b]
[b]6. 1[/b]


2.9
[b]1. 6[/b]
[b]2. 6.25[/b]
[b]3.1[/b]
[b]4. 1.5[/b]


2.1 program:

[b]import java.util.Scanner;[/b]


[b]public class CelsiusToFahrenheit {[/b]

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

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

[b]}[/b]


2.7 program


[b]import java.util.Scanner;[/b]
[b]import java.util.concurrent.TimeUnit;[/b]


[b]public class Convert {[/b]

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

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

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




[b]}[/b]
[b]}[/b]

Link to comment
Share on other sites

[quote name='K.A.Paul' timestamp='1320300625' post='3059590']
2.2


[b]public static final int SIZE = 10;[/b]

2.4


[b]1. A=5[/b]
[b]2. A=15[/b]
[b]3. A=1[/b]
[b]4. D=9.0[/b]
[b]5. D=7.5[/b]
[b]6. D=-4.5[/b]


2.5

[b]1. 2[/b]
[b]2. 2[/b]
[b]3. -4[/b]
[b]4. -4[/b]
[b]5. 0[/b]
[b]6. 1[/b]


2.9
[b]1. 6[/b]
[b]2. 6.25[/b]
[b]3.1[/b]
[b]4. 1.5[/b]


2.1 program:

[b]import java.util.Scanner;[/b]


[b]public class CelsiusToFahrenheit {[/b]

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

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

[b]}[/b]


2.7 program


[b]import java.util.Scanner;[/b]
[b]import java.util.concurrent.TimeUnit;[/b]


[b]public class Convert {[/b]

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

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

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




[b]}[/b]
[b]}[/b]
[/quote]


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

Link to comment
Share on other sites

[quote name='k2s' timestamp='1320300727' post='3059593']


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

next mnth nunchi start chesta baa &D_@@

Link to comment
Share on other sites

×
×
  • Create New...