Professional Documents
Culture Documents
Java Chapter 6 HW PDF
Java Chapter 6 HW PDF
HW Chap 06
Name: Md. Jeyson Jaman Sawan
Roll: CSE202101001
Level 1 Programming Exercises★
06. Write a program to print out the numbers 10 through 49 in the following manner:
Solution:
07. A prime number is an integer greater than 1 and divisible by only itself and 1. The first seven
prime numbers are 2, 3, 5, 7, 11, 13, and 17. Write a method that returns true if its parameter is
a prime number. Using this method, write a program that repeatedly asks the user for input
and displays Prime if the input is a prime number and Not Prime, otherwise. Stop the repetition
when the input is a negative number.
Solution:
Level 2 Programming Exercises ★★
18. Write a method that returns the number of digits in an integer argument; for example, 23,498 has five
digits. Using this method, write a program that repeatedly asks for input and displays the number of digits
the input integer has. Stop the repetition when the input value is negative.
Solution:
24. Write a program that inputs N, where 3<= N <= 25, and outputs a cross. The following figure shows
the output when N is 5.
Solution:
package myutil;
public Person( ) {
name = "Unknown";
return name;
this.name = name;
}
package ch7_level01_14;
import myutil.Person;
obj.setName("JJ Sawan");
System.out.println(obj.getName());
package myutil;
public MealCard(){
points=100;
return points;
this.points= points+p;
if((this.points-price)>0){
this.points= points-price;
}
else
package ch7_level01_14;
import java.util.Scanner;
import myutil.MealCard;
System.out.println("You have bought 1st food item. Price of this food item is: ");
foodprice=sc.nextInt();
obj1.FoodPurchase(foodprice);
System.out.println("You have bought 2nd food item. Price of this food item is: ");
foodprice=sc.nextInt();
obj1.FoodPurchase(foodprice);
point=sc.nextInt();
obj1.PurchasePoints(point);