Exercise From Chapter 12 To Chapter 19 Programming Exercises
Exercise From Chapter 12 To Chapter 19 Programming Exercises
Exercise From Chapter 12 To Chapter 19 Programming Exercises
1. Source Code:
Hasil Compile :
2. Source Code:
Hasil Compile :
3. Source Code :
Hasil Compile :
4. Source Code :
Hasil Compile :
5. Source Code :
Hasil Compile :
5b.Source Code :
Hasil Compile :
6. Source Code :
Hasil Compile :
7. Source Code :
8. Source Code :
Hasil Compile :
9. Source Code :
Hasil Compile :
Chapter 13
1. Source Code :
Hasil Compile :
2. Source Code :
Hasil Compile :
3. Source Code :
Hasil Compile :
4. Source Code :
Hasil Compile :
Chapter 14
1. Source Code :
Hasil Compile :
2. Source Code :
Hasil Compile :
3. Source Code :
Hasil Compile :
4. Source Code :
Hasil Compile :
Chapter 15
1. Source Code :
import java.util.Scanner;
class no1
{
public static void main (String[] args)
{
Scanner scan = new Scanner( System.in );
int nilaiAwal ;
int nilaiAkhir;
nilaiAwal = nilaiAwal + 1;
}
System.out.println( "Done" );
}
}
2. Source Code :
import java.util.Scanner;
class no2
{
public static void main (String[] args)
{
int i = 0;
System.out.println("Input Teks:");
String har = scan.nextLine();
int ok = har.length();
while ( i <= ok )
{
System.out.println( "count is:" + har );
i++;
}
System.out.println( "Done with the loop" );
}
}
3. Source Code :
import java.util.Scanner;
class no3 {
public static void main (String[] args) {
int count = 0;
int limit = 30;
int num;
System.out.println("Input Num:");
num = scan.nextInt();
System.out.print(name);
}
System.out.print(num);
}
}
Chapter 16
1. Source Code :
import java.util.Scanner;
class addedinteger
{public static void main(String[]args)
{String num;
String a;
Scanner scan = new Scanner(System.in);
System.out.println("How Many Integers Will Be Added : ");
num=scan.nextLine();
int A,b,Num,i;
b=0;
Num=Integer.parseInt(num);
for(i=1;i<=Num;i++)
{System.out.println("Enter an integer :");
a=scan.nextLine();
A=Integer.parseInt(a);
b=b+A;
}
System.out.print("The sum is "+b);
}
}
2. Source Code :
import java.util.Scanner;
class adding
{public static void main(String[]args)
{String sums;
Scanner scan=new Scanner(System.in);
System.out.println("Enter N : ");
sums=scan.nextLine();
int i,a;
double m,n;
n=0;
a=Integer.parseInt(sums);
for(i=1;i<=a;i++)
{m=1.0/i;
n=n+m;
}
System.out.print("Sum is : "+n);
}
}
3. Source Code :
import java.util.Scanner;
class pangkat
{public static void main(String[]args)
{String N;
String X;
Scanner scan = new Scanner(System.in);
System.out.println("Enter N: ");
N=scan.nextLine();
int i;
double n,x,a,b;
a=0;
b=0;
n=Integer.parseInt(N);
System.out.println("X X^2");
for(i=1; i<=n;i++)
{X=scan.nextLine();
x=Integer.parseInt(X);
System.out.println(x+" "+x*x);
a=a+x;
b=b+x*x;
}
System.out.println(a+" "+b);
}
}
Chapter 17
4. Source Code :
import java.util.Scanner;
class wedge
{
public static void main(String[]args)
{String a;
Scanner scan=new Scanner(System.in);
System.out.print("Enter the height : ");
a=scan.nextLine();
int i,j,A;
A=Integer.parseInt(a);
for(i=1;i<=A;i=i+1)
{for(j=1;j<=A+1-i;j=j+1)
{System.out.print("*");
}System.out.println("");}
}
}
5. Source Code :
import java.util.Scanner;
class pine
{public static void main(String[]args)
{String a;
Scanner scan=new Scanner(System.in);
System.out.print("Enter the height : ");
a=scan.nextLine();
int i,j,k,l,m,n,A;
A=Integer.parseInt(a);
for(i=1;i<=A;i=i+1)
{for(j=1;j<=A+1-i;j=j+1)
{System.out.print(" ");
}
for(k=1;k<=2*i-1;k++)
{System.out.print("*");}
System.out.println("");}
for(n=1;n<=3;n++)
{for(m=1;m<=A-1;m++)
{System.out.print(" ");}
for(l=1;l<=3;l++)
{System.out.print("*"); }
System.out.println("");
}
}
}
Chapter 18
1. Source Code :
import java.util.Scanner;
class galon
{public static void main(String[]args)
{String star;
String finis;
String galon;
Scanner scan = new Scanner(System.in);
System.out.println("Miles per Gallon Program");
int start,end,gallon;
double hasil;
start=1;
while(start>=0)
{System.out.println("Initial miles : ");
star=scan.nextLine();
start=Integer.parseInt(star);
if(start>=0)
{System.out.println("Final miles : ");
finis=scan.nextLine();
end=Integer.parseInt(finis);
System.out.println("Gallons : ");
galon=scan.nextLine();
gallon=Integer.parseInt(galon);
hasil=(end-start)/10;
System.out.println("Miles Per Gallon: "+hasil);
}
}
System.out.println("bye");
}
}
2. Source Code :
import java.util.Scanner;
class adder
{public static void main(String[]args)
{String low;
String high;
String Data;
Scanner scan = new Scanner(System.in);
data=1;
while(data>0)
{System.out.println("Enter Data = ");
Data=scan.nextLine();
data=Integer.parseInt(Data);
if(data>=Low && data<=High)
{n=n+data;}
else{m=m+data;}
}
System.out.println("Sum of in range values = "+n);
System.out.println("Sum of out range values = "+m);
}
}
3. Source Code :
import java.util.Scanner;
class shipping
{
public static void main(String[]args)
{
String Berat;
Scanner scan = new Scanner(System.in);
int berat;
double b;
berat=1;
while(berat> 0)
{
System.out.println("Weight of order:");
Berat=scan.nextLine();
berat=Integer.parseInt(Berat);
b=3+(0.25*(berat-10));
if(berat>0&&berat<=10)
System.out.println("Shipping Cost: $3.00 ");
if(berat>10)
System.out.println("Shipping Cost:$"+b);
}
{System.out.println("bye");}
}
}
4. Source Code :
import java.util.Scanner;
class rectangular
{public static void main(String[]args)
{String firstx,firsty,secondx,secondy;
Scanner scan = new Scanner(System.in);
System.out.println("Computer Aided Design Program");
int a,b,c,fx,fy,sx,sy;
a=1;
b=1;
while(a>0)
{System.out.println("First corner X coordinate:");
firstx=scan.nextLine();
fx=Integer.parseInt(firstx);
System.out.println("First corner Y coordinate:");
firsty=scan.nextLine();
fy=Integer.parseInt(firsty);
System.out.println("Second corner X coordinate:");
secondx=scan.nextLine();
sx=Integer.parseInt(secondx);
System.out.println("Second corner Y coordinate:");
secondy=scan.nextLine();
sy=Integer.parseInt(secondy);
a=sx-fx;
b=sy-fy;
c=a*b;
if(a<0)
{a=a*-1;}
if(b<0)
{b=b*-1;}
System.out.println("Width = "+a+" Height = "+b+" Area = "+c);
System.out.println("");
}System.out.println("Finished");
}}
5. Source Code :
import java.util.Scanner;
class login
{
public static void main (String[]args)
{
String Username;
String Pass;
Scanner scan = new Scanner(System.in);
int a;
a=1;
while(a>0)
{System.out.println("Username: ");
Username=scan.nextLine();
System.out.println("Password: ");
Pass=scan.nextLine();
if(Username.equals("quit")&&Pass.equals("exit"))
{a=0;}
else{if(Username.equals("joy")&&Pass.equals("sun"))
{System.out.println("You have logged on with priority 4");}
else{ if(Username.equals("gates")&&Pass.equals("monopoly"))
{System.out.println("You have logged on with priority 1");}
else{if(Username.equals("jobs")&&Pass.equals("apple"))
{System.out.println("You have logged on with priority 3");}
else{if(Username.equals("root")&&Pass.equals("secret"))
{System.out.println("You have logged on with priority 5");}
else{System.out.println("Logon Failed");}}
}}
Username="";
Pass="";
}
}
System.out.println("System Shutting Down");
System.out.println("bye");}}
Chapter 19
1. Source Code :
import java.util.Scanner;
class pay
{public static void main(String[]args)
{String pay;
Scanner scan = new Scanner(System.in);
System.out.println("Enter The Monthly Payments");
pay=scan.nextLine();
int i;
i=1;
double bayar,hasil;
bayar=Integer.parseInt(pay);
hasil=1000;
while(hasil>0)
{System.out.print("Month: "+i+" ");
hasil=hasil+(hasil*15/1000)-bayar;
System.out.print("balance: "+hasil+" ");
System.out.println("Total Payments: "+i*bayar);
i++;
}
}
}
2. Source Code:
import java.util.Scanner;
class drug
{public static void main(String[]args)
{String effect;
Scanner scan = new Scanner(System.in);
System.out.println("Enter The Effectiveness : ");
effect = scan.nextLine();
double efek;
int i;
i=0;
efek = Integer.parseInt(effect);
System.out.print("month : "+i+" effectiveness : "+efek);
System.out.println("");
i=i+1;
while(efek>50)
{efek=efek-(efek*4/100);
System.out.print("month : "+i+" effectiveness : "+efek);
System.out.println("");
i++;
}
}
}